<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>切片自己练习</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        #div01{
            width: 500px;
            background-color: #99ff99;
            margin: 50px auto;
            text-align: center;
        }
    </style>
    <script>
        window.onload=function () {
            var div01=document.getElementById("div01");
            var btn01=document.getElementById("btn01");
            var btn02=document.getElementById("btn02");
            var img=document.getElementsByTagName("img")[0];
            var imgArr=["../imagconman/1.jpg","../imagconman/2.jpg","../imagconman/3.jpg","../imagconman/4.jpg","../imagconman/5.jpg"];
            var index=0;
            var pid=document.getElementById("pid");
                pid.innerHTML="共"+imgArr.length+"张，当前第"+(index+1)+"张";
                btn01.onclick=function () {
                //点击btn01 向上翻一页
                    index--;
                    if (index<0){
                        index=imgArr.length-1;
                    }
                   img.src=imgArr[index];
                    pid.innerHTML="共"+imgArr.length+"张，当前第"+(index+1)+"张";
                };
            btn02.onclick=function () {
                //点击btn02 向下翻一页
                index++;
                if (index>imgArr.length-1){
                    index=0;
                }
                img.src=imgArr[index];
                pid.innerHTML="共"+imgArr.length+"张，当前第"+(index+1)+"张";
            };
        }
    </script>
</head>
<body>
<div id="div01">
    <p id="pid"></p>
    <img src="../imagconman/1.jpg" alt="冰棍">
    <button id="btn01">上一张</button>
    <button id="btn02">下一张</button>
</div>
</body>
</html>